package skyproc;

import java.io.Serializable;
import java.util.Objects;
import skyproc.SubStringPointer.Files;

/**
 * An extended major record that has a name. (FULL record)
 *
 * @author Justin Swanson
 */
public abstract class MajorRecordNamed extends MajorRecord implements Serializable {

    SubStringPointer FULL = new SubStringPointer(Type.FULL, Files.STRINGS);

    MajorRecordNamed() {
        super();
        subRecords.add(FULL);
    }

    MajorRecordNamed(Mod mod, String edid) {
        super(mod, edid);
        subRecords.add(FULL);
    }

    /**
     * Returns the in-game name of the Major Record.
     *
     * @return
     */
    public String getName() {
        return FULL.print();
    }

    /**
     * Sets the in-game name of the Major Record.
     *
     * @param in The string to set the in-game name to.
     */
    public void setName(String in) {
        FULL.text.setString(in);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final MajorRecordNamed other = (MajorRecordNamed) obj;
        if (!Objects.equals(this.FULL, other.FULL)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 53 * hash + Objects.hashCode(this.FULL);
        return hash;
    }

    /**
     * Merges Major Records with names. Implements MajorRecord's merger.
     *
     * @param no The new MajorRecordNamed to be merged.
     * @param bo The base MajorRecordNamed, to prevent base data from being
     * re-merged.
     * @return The modified MajorRecordNamed.
     */
    @Override
    public MajorRecord merge(MajorRecord no, MajorRecord bo) {
        super.merge(no, bo);
        MajorRecordNamed m = this;
        if (!(no == null && bo == null && (no instanceof MajorRecordNamed) && (bo instanceof MajorRecordNamed))) {
            final MajorRecordNamed nm = (MajorRecordNamed) no;
            final MajorRecordNamed bm = (MajorRecordNamed) bo;
            m.FULL.merge(nm.FULL, bm.FULL);
        }
        return m;
    }
}
